//
//  NCChatAudioTipsView.m
//  FBRetainCycleDetector
//
//  Created by LINAICAI on 2018/5/10.
//

#import "NCChatAudioTipsView.h"
#import <Masonry.h>
@interface NCChatAudioTipsView()
@property(nonatomic , strong)UILabel *label;
@property(nonatomic , strong)UIImageView *imageView;
@end
@implementation NCChatAudioTipsView
+ (void)show:(NSString *)string inView:(UIView *)view{
    
    NCChatAudioTipsView *tipsView = [[NCChatAudioTipsView alloc]init];
    tipsView.label.text = string;
    [view addSubview:tipsView];
    [tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(view);
        make.height.mas_equalTo(0);
    }];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [tipsView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(50);
        }];
        [tipsView layoutIfNeeded];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:0.25 animations:^{
                tipsView.alpha = 0.0;
            } completion:^(BOOL finished) {
                [tipsView removeFromSuperview];
            }];
        });

    });
    
}
- (UILabel *)label
{
    if (!_label) {
        _label = [[UILabel alloc]init];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:15];
    }
    return _label;

}
- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc]initWithImage:[NCChatUIImage(@"audio_left_3") imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _imageView.tintColor = [UIColor whiteColor];
    }
    return _imageView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor colorWithRed:67/255.0 green:177/255.0 blue:255/255.0 alpha:0.9];
        [self addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.mas_offset(20);
            make.size.mas_equalTo(CGSizeMake(25, 25));
        }];
        [self addSubview:self.label];
        [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(self.imageView.mas_right).mas_offset(20);
        }];
    }
    return self;
}
@end
